package com.wc.算法基础课.B第二讲数据结构.单链表.双链表;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/4/30 17:22
 * @description https://www.acwing.com/problem/content/829/
 */
public class Main {
    /**
     * 数组模拟双链表
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 100010, idx = 2;
    static int[] e = new int[N], l = new int[N], r = new int[N];
    static int m;

    // 第k个是第k + 1,因为idx 是从2开始的
    public static void main(String[] args) {
        m = sc.nextInt();
        init();
        while (m-- > 0) {
            String op = sc.next();
            int k, x;
            if (op.equals("L")) {
                x = sc.nextInt();
                add(0, x);
            } else if (op.equals("R")) {
                x = sc.nextInt();
                add(l[1], x);
            } else if (op.equals("D")) {
                k = sc.nextInt();
                remove(k + 1);
            } else if (op.equals("IL")) {
                k = sc.nextInt();
                x = sc.nextInt();
                add(l[k + 1], x);
            } else {
                k = sc.nextInt();
                x = sc.nextInt();
                add(k + 1, x);
            }
        }
        for(int i = r[0]; i != 1; i = r[i]) out.print(e[i] + " ");
        out.flush();
    }

    static void init() {
        r[0] = 1;
        l[1] = 0;
    }

    static void add(int k, int x) {
        e[idx] = x;
        r[idx] = r[k];
        l[idx] = k;
        l[r[k]] = idx;
        r[k] = idx++;
    }

    static void remove(int k) {
        int a = l[k], b = r[k];
        r[a] = b;
        l[b] = a;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}